package andriod.action.flow;

import andriod.service.ArdFlowService;

import com.jcrj.action.BaseAction;
import com.jcrj.entity.OFile;
import com.jcrj.entity.OFlowFormProporty;
import com.jcrj.entity.OFormDefinition;
import com.jcrj.entity.OFormProporty;
import com.jcrj.entity.OLeave;
import com.jcrj.entity.ONode;
import com.jcrj.entity.OProcessinstance;
import com.jcrj.entity.OUser;
import com.jcrj.entity.OWorkflow;
import com.jcrj.service.FielTransactService;
import com.jcrj.service.FileService;
import com.jcrj.service.FlowFormService;
import com.jcrj.service.HolidayService;
import com.jcrj.service.TaskService;
import com.jcrj.service.WorkflowManagerService;
import com.jcrj.util.DateProcessor;
import com.jcrj.util.DateUtil;
import com.jcrj.util.FielAll;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class ArdFlowAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private ArdFlowService ardFlowService;
	private WorkflowManagerService workflowManagerService;
	private FielTransactService fielTransactService;
	private TaskService taskService;
	private FlowFormService flowFormService;
	private int flowId;
	private int tableId;
	private String name; // 查询条件
	private long totalCount; // 记录总数
	private long pageCount; // 总页数
	private FileService fileService;
	
	public void setFileService(FileService fileService) {
		this.fileService = fileService;
	}
	

	public String flowHome() {
		try {
			JSONObject obj = new JSONObject();
			OUser user = (OUser) getSession().get("userInfo");
			List agents = this.taskService.getAgentUser(user);
			String process = this.workflowManagerService
					.getSqlProcessinstanceList(user.getId().intValue(), agents);
			long count = this.ardFlowService.countWorkFlowTaskFile(process,
					null).longValue();
			obj.put("waitCount", Long.valueOf(count));
			process = this.workflowManagerService
					.getSqlDoneProcessinstanceList(user.getId().intValue());
			count = this.ardFlowService.countWorkFlowTaskFile(process, null)
					.longValue();
			obj.put("overCount", Long.valueOf(count));
			agents = this.taskService.getAgentUser(user);
			process = this.workflowManagerService.getSqlProcessinstanceList(
					user.getId().intValue(), agents);
			count = this.ardFlowService.countWorkFlowTaskFile(process, user)
					.longValue();
			obj.put("rejectCount", Long.valueOf(count));
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getFlowTypes() {
		try {

			List flowList = this.workflowManagerService.workFlowTypeList();
			JsonConfig config = new JsonConfig();
			config.registerJsonValueProcessor(Date.class, new DateProcessor());
			config.registerJsonValueProcessor(java.util.Date.class,
					new DateProcessor());

			JSONArray workListArray = JSONArray.fromObject(flowList, config);
			// JSONArray workListArray = JSONArray.fromObject(flowList);
			// JSONObject obj = new JSONObject();

			// obj.put("flowTypes", workListArray);

			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(workListArray.toString());
			super.getResponse().getWriter().flush();

		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getOrgWorkFlow() {
		try {
			OUser ou = (OUser) super.getSession().get("userInfo");
			List workList = this.workflowManagerService.getOrgWorkFlow(ou);
			List flowTypeList = null;
			if (workList.size() > 0) {
				flowTypeList = this.workflowManagerService
						.getFlowTypeList(workList);
			}

			JsonConfig config = new JsonConfig();
			config.registerJsonValueProcessor(Date.class, new DateProcessor());

			JSONArray workListArray = JSONArray.fromObject(workList, config);
			JSONArray flowTypeArray = JSONArray
					.fromObject(flowTypeList, config);

			JSONObject obj = new JSONObject();

			obj.put("flowTypeList", flowTypeArray);
			obj.put("workList", workListArray);

			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();

		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String waitWorkFlowTaskFile() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			List agents = this.taskService.getAgentUser(user);
			String process = this.workflowManagerService
					.getSqlProcessinstanceList(user.getId().intValue(), agents);
			// /* 79 */ List fielAll =
			// this.ardFlowService.getWorkFlowTaskfile(process,
			// /* 80 */ null);

			List fielAll = this.fielTransactService.getWorkFlowTaskfile(
					process, super.getCurrentPage(), this.name, null,
					super.getStartDate(), super.getEndDate());

			int i = 0;
			for (int sel = fielAll.size(); i < sel; i++) {
				if (isNumeric(((FielAll) fielAll.get(i)).getSender())) {
					String count = ((FielAll) fielAll.get(i)).getSender();
					((FielAll) fielAll.get(i)).setSender(this.taskService
							.getUserNameNew(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getSender())).getName());
					((FielAll) fielAll.get(i)).setUnit(this.fielTransactService
							.getUserAllOrgName(this.taskService
									.getUserNameNew(Integer.parseInt(count))
									.getOrgId().intValue()));
				}
				if (isNumeric(((FielAll) fielAll.get(i)).getFlow())) {
					((FielAll) fielAll.get(i))
							.setTitle(this.fielTransactService.getWorkFlow(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getFlow())).getName());
					((FielAll) fielAll.get(i)).setFlow("工作流程");
				}
			}

			JsonConfig config = new JsonConfig();
			config.registerJsonValueProcessor(Date.class, new DateProcessor());
			JSONObject obj = new JSONObject();
			JSONArray array = JSONArray.fromObject(fielAll, config);

			this.totalCount = this.fielTransactService.countWorkFlowTaskFile(
					process, this.name, null, super.getStartDate(),
					super.getEndDate()).longValue();
			this.pageCount = ((this.totalCount - 1L) / 10L + 1L);

			obj.put("totalCount", this.totalCount);
			obj.put("pageCount", this.pageCount);
			obj.put("currentPage", super.getCurrentPage());
			obj.put("list", array);
			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String overWorkFlowTaskFile() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			String process = this.workflowManagerService
					.getSqlDoneProcessinstanceList(user.getId().intValue());

			// /* 124 */ List fielAll =
			// this.ardFlowService.getWorkFlowTaskfile(process,
			// /* 125 */ null);

			List fielAll = this.fielTransactService.getWorkFlowTaskfile(
					process, super.getCurrentPage(), this.name, null,
					super.getStartDate(), super.getEndDate());

			int i = 0;
			for (int sel = fielAll.size(); i < sel; i++) {
				if (isNumeric(((FielAll) fielAll.get(i)).getSender())) {
					String count = ((FielAll) fielAll.get(i)).getSender();
					((FielAll) fielAll.get(i)).setSender(this.taskService
							.getUserNameNew(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getSender())).getName());
					((FielAll) fielAll.get(i)).setUnit(this.fielTransactService
							.getUserAllOrgName(this.taskService
									.getUserNameNew(Integer.parseInt(count))
									.getOrgId().intValue()));
				}
				if (isNumeric(((FielAll) fielAll.get(i)).getFlow())) {
					((FielAll) fielAll.get(i))
							.setTitle(this.fielTransactService.getWorkFlow(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getFlow())).getName());
					((FielAll) fielAll.get(i)).setFlow("工作流程");
				}
			}

			JsonConfig config = new JsonConfig();
			config.registerJsonValueProcessor(Date.class, new DateProcessor());
			JSONArray array = JSONArray.fromObject(fielAll, config);

			JSONObject obj = new JSONObject();
			// /* 148 */ //obj.put("list", fielAll);

			this.totalCount = this.fielTransactService.countWorkFlowTaskFile(
					process, this.name, null, super.getStartDate(),
					super.getEndDate()).longValue();
			this.pageCount = ((this.totalCount - 1L) / 10L + 1L);

			obj.put("totalCount", this.totalCount);
			obj.put("pageCount", this.pageCount);
			obj.put("currentPage", super.getCurrentPage());
			obj.put("list", array);

			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String rejectWorkFlowTaskFile() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			List agents = this.taskService.getAgentUser(user);
			String process = this.workflowManagerService
					.getSqlProcessinstanceList(user.getId().intValue(), agents);

			// List fielAll = this.ardFlowService.getWorkFlowTaskfile(process,
			// user);
			List fielAll = this.fielTransactService.getWorkFlowTaskfile(
					process, super.getCurrentPage(), this.name, user,
					super.getStartDate(), super.getEndDate());

			int i = 0;
			for (int sel = fielAll.size(); i < sel; i++) {
				if (isNumeric(((FielAll) fielAll.get(i)).getSender())) {
					String count = ((FielAll) fielAll.get(i)).getSender();
					((FielAll) fielAll.get(i)).setSender(this.taskService
							.getUserNameNew(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getSender())).getName());
					((FielAll) fielAll.get(i)).setUnit(this.fielTransactService
							.getUserAllOrgName(this.taskService
									.getUserNameNew(Integer.parseInt(count))
									.getOrgId().intValue()));
				}
				if (isNumeric(((FielAll) fielAll.get(i)).getFlow())) {
					((FielAll) fielAll.get(i))
							.setTitle(this.fielTransactService.getWorkFlow(
									Integer.parseInt(((FielAll) fielAll.get(i))
											.getFlow())).getName());
					((FielAll) fielAll.get(i)).setFlow("工作流程");
				}
			}
			JsonConfig config = new JsonConfig();
			config.registerJsonValueProcessor(Date.class, new DateProcessor());
			JSONObject obj = new JSONObject();

			JSONArray array = JSONArray.fromObject(fielAll, config);
			// obj.put("list", fielAll);

			this.totalCount = this.fielTransactService.countWorkFlowTaskFile(
					process, this.name, user, super.getStartDate(),
					super.getEndDate()).longValue();
			this.pageCount = ((this.totalCount - 1L) / 10L + 1L);

			obj.put("totalCount", this.totalCount);
			obj.put("pageCount", this.pageCount);
			obj.put("currentPage", super.getCurrentPage());
			obj.put("list", array);

			/* 195 */super.getResponse().setCharacterEncoding("UTF-8");
			/* 196 */super.getResponse().getWriter().write(obj.toString());
			/* 197 */super.getResponse().getWriter().flush();
			/*     */} catch (Exception e) {
			/* 199 */e.printStackTrace();
			/*     */try
			/*     */{
				/* 202 */super.getResponse().getWriter().close();
				/*     */} catch (IOException e1) {
				/* 204 */e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	private Map<String, List<OFile>> getFileList(List<OFlowFormProporty> proportyList,String jsonData){
		List<String> fileClumns = new ArrayList<String>();
		for (OFlowFormProporty formProporty : proportyList) {
			if(formProporty.getType().equals("upload")){
				fileClumns.add(formProporty.getColumnName());
			}
		}
		
		JSONArray jsonDataArray = JSONArray.fromObject(jsonData);
		Map<String, List<OFile>> fileMap = new HashMap<String, List<OFile>>();
		if(!fileClumns.isEmpty()){
			for(int i=0;i<jsonDataArray.size();i++){
				JSONObject data = jsonDataArray.getJSONObject(i);
				String columnName = data.getString("name");
				if(null==columnName)continue;
				if(fileClumns.contains(columnName)){
					List<OFile> fileList = this.fileService.getFileList(data.getString("value"));
					fileMap.put(columnName, fileList);
				}
			}
		}
		return fileMap;
	}

	public String getWorkFlowSign() {
		try {
			JSONObject obj = new JSONObject();
			OWorkflow workflow = this.workflowManagerService
					.getWorkflow(this.flowId);
			obj.put("workflow", workflow);
			OFormDefinition definition = this.flowFormService
					.getFormDefinition(workflow.getFormId().intValue());
			String content = definition.getContent();
			List<String> ids = getIds(content);
			List<OFlowFormProporty> list = this.flowFormService
					.flowFormProportyList(definition.getId());
			Map<String, OFlowFormProporty> map = new HashMap<String, OFlowFormProporty>();
			for (OFlowFormProporty formProporty : list) {
				map.put(formProporty.getColumnName(), formProporty);
			}
			List<OFlowFormProporty> resultList = new ArrayList<OFlowFormProporty>();
			for (String id : ids) {
				resultList.add(map.get(id));
			}

			obj.put("definition", resultList);
			String jsonData = this.flowFormService.getFormContent(
					definition.getFormId(), this.tableId);
			obj.put("jsonData", jsonData);
			obj.put("fileList", getFileList(resultList, jsonData));
			String instanceId = this.flowFormService.getInstanceId(definition
					.getFormId().intValue(), this.tableId);
			obj.put("instanceId", instanceId);
			OProcessinstance instance = this.workflowManagerService
					.getProcessinstance(Integer.parseInt(instanceId));
			obj.put("instance", instance);
			List nodeList = this.workflowManagerService.getNextNode(instance
					.getNodeId().intValue());
			obj.put("nodeList", nodeList);
			List backNotes = this.workflowManagerService.getBackNodeList(
					instance.getId().intValue(), instance.getNodeId()
							.intValue());
			obj.put("backNotes", backNotes);
			
			OUser user = (OUser) getRequest().getSession().getAttribute("userInfo");
			instanceId = this.flowFormService.getInstanceId(definition.getFormId().intValue(), this.tableId);
			instance = this.workflowManagerService.getProcessinstance(Integer.parseInt(instanceId));
			
			if (definition.getFormId() == 86) {
				obj.put("holidayTotal", getMyHolidayTotal(""+instance.getUserId()));
			} else if (definition.getFormId() == 341) {
				obj.put("leaveTotal", getMyLeaveTotal(""+instance.getUserId()));
			}
			obj.put("writableProperty", initFormValueWrite(""+instance.getNodeId(), user));
			obj.put("tableId", this.tableId);
			obj.put("formId", definition.getFormId());
			obj.put("userInfo", user);
			
			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getWorkFlowView() {
		try {
			JSONObject obj = new JSONObject();
			OWorkflow workflow = this.workflowManagerService
					.getWorkflow(this.flowId);
			obj.put("workflow", workflow);
			//表单控件
			OFormDefinition definition = this.flowFormService
					.getFormDefinition(workflow.getFormId().intValue());
			String content = definition.getContent();
			List<String> ids = getIds(content);
			List<OFlowFormProporty> list = this.flowFormService
					.flowFormProportyList(definition.getId());
			Map<String, OFlowFormProporty> map = new HashMap<String, OFlowFormProporty>();
			for (OFlowFormProporty formProporty : list) {
				map.put(formProporty.getColumnName(), formProporty);
			}
			List<OFlowFormProporty> resultList = new ArrayList<OFlowFormProporty>();
			for (String id : ids) {
				resultList.add(map.get(id));
			}
			obj.put("definition", resultList);
			
			String instanceId = this.flowFormService.getInstanceId(definition
					.getFormId().intValue(), this.tableId);
			obj.put("instanceId", instanceId);
			
			String jsonData = this.flowFormService.getFormContent(
					definition.getFormId(), this.tableId);
			obj.put("jsonData", jsonData);
			
			obj.put("formId", definition.getFormId());
			obj.put("tableId", this.tableId);
			obj.put("fileList", getFileList(resultList, jsonData));
			
			
			
//			if (definition.getFormId() == 86) {
//				obj.put("holidayTotal", getMyHolidayTotal(null));
//			} else if (definition.getFormId() == 341) {
//				obj.put("leaveTotal", getMyLeaveTotal(null));
//			}
			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	/**
	 * 需要的参数
	 * this.tableId
	 * this.flowId
	 * 
	 * 
	 * @return
	 */
	public String workFlowFormBack() {
		try {
			JSONObject obj = new JSONObject();
			OWorkflow workflow = this.workflowManagerService
					.getWorkflow(this.flowId);
			obj.put("workflow", workflow);
			OFormDefinition definition = this.flowFormService
					.getFormDefinition(workflow.getFormId().intValue());
			
			String content = definition.getContent();
			List<String> ids = getIds(content);
			List<OFlowFormProporty> list = this.flowFormService
					.flowFormProportyList(definition.getId());
			Map<String, OFlowFormProporty> map = new HashMap<String, OFlowFormProporty>();
			for (OFlowFormProporty formProporty : list) {
				map.put(formProporty.getColumnName(), formProporty);
			}
			List<OFlowFormProporty> resultList = new ArrayList<OFlowFormProporty>();
			for (String id : ids) {
				resultList.add(map.get(id));
			}
			obj.put("definition", resultList);
			ONode node = this.workflowManagerService.getStartNode(this.flowId);
			obj.put("node", node);
			OUser oUser = (OUser) getRequest().getSession().getAttribute("userInfo");
			obj.put("writableProperty", initFlowFormValueWrite(flowId, oUser));
			
			obj.put("userInfo", oUser);
			
			String jsonData = this.flowFormService.getFormContent(
					definition.getFormId(), this.tableId);
			obj.put("jsonData", jsonData);
			
			obj.put("fileList", getFileList(resultList, jsonData));
			
			String instanceId = this.flowFormService.getInstanceId(definition
					.getFormId().intValue(), this.tableId);
			obj.put("instanceId", instanceId);
			
//			if (definition.getFormId() == 86) {
//				obj.put("holidayTotal", getMyHolidayTotal(null));
//			} else if (definition.getFormId() == 341) {
//				obj.put("leaveTotal", getMyLeaveTotal(null));
//			}
			
			obj.put("tableId", tableId);
			obj.put("formId", definition.getFormId());
			super.getResponse().setCharacterEncoding("UTF-8");
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String deleteWorkFlowData() {
		try {
			this.workflowManagerService.deleteWorkFlow(this.flowId,
					this.tableId);
			JSONObject obj = new JSONObject();
			obj.put("flag", Boolean.valueOf(true));
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String workFlowFormDraft() {
		OWorkflow workflow = this.workflowManagerService
				.getWorkflow(this.flowId);
		JSONObject obj = new JSONObject();
		obj.put("workflow", workflow);
		OFormDefinition definition = this.flowFormService
				.getFormDefinition(workflow.getFormId().intValue());
		String content = definition.getContent();
		List<String> ids = getIds(content);
		List<OFlowFormProporty> list = this.flowFormService
				.flowFormProportyList(definition.getId());
		Map<String, OFlowFormProporty> map = new HashMap<String, OFlowFormProporty>();
		for (OFlowFormProporty formProporty : list) {
			map.put(formProporty.getColumnName(), formProporty);
		}
		List<OFlowFormProporty> resultList = new ArrayList<OFlowFormProporty>();
		for (String id : ids) {
			resultList.add(map.get(id));
		}

		obj.put("definition", resultList);
		// obj.put("definition", definition);
		ONode node = this.workflowManagerService.getStartNode(this.flowId);
		obj.put("node", node);
		obj.put("formId", definition.getFormId());
		obj.put("tableId", this.tableId);

		if (definition.getFormId() == 86) {
			obj.put("holidayTotal", getMyHolidayTotal(null));
		} else if (definition.getFormId() == 341) {
			obj.put("leaveTotal", getMyLeaveTotal(null));
		}
		
		OUser oUser = (OUser) getRequest().getSession().getAttribute("userInfo");
		
		obj.put("writableProperty", initFlowFormValueWrite(flowId, oUser));
		
		obj.put("userInfo", oUser);

		super.getResponse().setCharacterEncoding("UTF-8");
		try {
			super.getResponse().getWriter().write(obj.toString());
			super.getResponse().getWriter().flush();

		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	public List<OFlowFormProporty> initFormValueWrite(String nodeId,OUser user) {
			super.getResponse().setCharacterEncoding("utf-8");
			List<OFlowFormProporty> list = this.workflowManagerService.getWriteProportyList(nodeId, user);
			return list;
	}
	
	public List<OFlowFormProporty> initFlowFormValueWrite(int flowId,OUser user) {
		super.getResponse().setCharacterEncoding("utf-8");
		List<OFlowFormProporty> list = this.workflowManagerService.getChosenFlowPropertyList(flowId);
		return list;
	}
	

	private HolidayService holidayService;

	public void setHolidayService(HolidayService holidayService) {
		this.holidayService = holidayService;
	}

	private JSONObject getMyHolidayTotal(String userId) {
		long total = 0L;
		long preTotal = 0L;
		long preHoliday = 0L;
		OUser user = null;
		int year = Integer.parseInt(DateUtil.getYear());
		if ((userId == null) || ("".equals(userId)))
			user = (OUser) getSession().get("userInfo");
		else {
			user = this.holidayService.getUserObj(Integer.parseInt(userId));
		}
		JSONObject json = new JSONObject();
		if ((user.getWorkDate() != null)
				&& (!"".equals(user.getWorkDate()))) {
			int work = Integer.parseInt(user.getWorkDate());
			long nowHolidays = getHolidaysTotal(year, work, user.getId()
					.intValue());
			long preHolidays = getHolidaysTotal(year - 1, work, user
					.getId().intValue());
			if (nowHolidays > 0L) {
				total = this.holidayService.myHolidayTotal(
						user.getId().intValue(), year).longValue();
			}
			if (preHolidays > 0L) {
				preTotal = this.holidayService.myHolidayTotal(
						user.getId().intValue(), year - 1).longValue();
			}
			if (preHolidays - preTotal < 0L)
				preHoliday = 0L;
			else {
				preHoliday = preHolidays - preTotal;
			}
			json.put("preHoliday", Long.valueOf(preHoliday));
			json.put("nowHoliday", Long.valueOf(nowHolidays));
			json.put("total", Long.valueOf(total));
		} else {
			json.put("preHoliday", Integer.valueOf(0));
			json.put("nowHoliday", Integer.valueOf(0));
			json.put("total", Integer.valueOf(0));
		}
		return json;
	}

	private JSONObject getMyLeaveTotal(String userId) {
		int year = Integer.parseInt(DateUtil.getYear());
		OLeave leaves;
		if ((userId == null) || ("".equals(userId))) {
			OUser user = (OUser) getSession().get("userInfo");
			leaves = this.holidayService.myLeaveTotals(user.getId().intValue(),
					year);
		} else {
			leaves = this.holidayService.myLeaveTotals(
					Integer.parseInt(userId), year);
		}
		JSONObject json = new JSONObject();
		json.put("leave", leaves);
		return json;
	}

	private long getHolidaysTotal(int year, int work, int userId) {
		OLeave leaves = this.holidayService.myLeaveTotals(userId, year);
		long holidays = 0L;
		if ((Integer.parseInt(leaves.getDays1()) < 20)
				&& (Integer.parseInt(leaves.getDays2()) < 60)) {
			if ((year - work >= 1) && (year - work < 10))
				holidays = 5L;
			else if ((year - work >= 10) && (year - work < 20))
				holidays = 10L;
			else if (year - work >= 20) {
				holidays = 15L;
			}
		}
		return holidays;
	}

	private boolean isNumeric(String str) {
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);

		return isNum.matches();
	}

	public ArdFlowService getArdFlowService() {
		return this.ardFlowService;
	}

	public void setArdFlowService(ArdFlowService ardFlowService) {
		this.ardFlowService = ardFlowService;
	}

	public WorkflowManagerService getWorkflowManagerService() {
		return this.workflowManagerService;
	}

	public void setWorkflowManagerService(
			WorkflowManagerService workflowManagerService) {
		this.workflowManagerService = workflowManagerService;
	}

	public FlowFormService getFlowFormService() {
		return flowFormService;
	}

	public void setFlowFormService(FlowFormService flowFormService) {
		this.flowFormService = flowFormService;
	}

	public int getFlowId() {
		return flowId;
	}

	public void setFlowId(int flowId) {
		this.flowId = flowId;
	}

	public int getTableId() {
		return tableId;
	}

	public void setTableId(int tableId) {
		this.tableId = tableId;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public long getPageCount() {
		return pageCount;
	}

	public void setPageCount(long pageCount) {
		this.pageCount = pageCount;
	}

	public FielTransactService getFielTransactService() {
		return this.fielTransactService;
	}

	public void setFielTransactService(FielTransactService fielTransactService) {
		this.fielTransactService = fielTransactService;
	}

	public TaskService getTaskService() {
		return this.taskService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	private static List<String> getIds(String content) {
		List<String> list = new ArrayList<String>();
		Pattern pattern = Pattern.compile("id\\s*=\\s*\"jcoa[^\"]+" + "\"");
		System.out.println(pattern.pattern());
		Matcher matcher = pattern.matcher(content);
		while (matcher.find()) {
			String str = matcher.group();
			list.add(str.split("\"")[1]);
		}
		return list;
	}

}